<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>管理员登录-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
  <!--  <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />-->
    <link rel="stylesheet" href="../static/css/font.css">
	<link rel="stylesheet" href="../static/css/weadmin.css">
    <script src="../static/layui/layui.js" charset="utf-8"></script>

</head>
<body class="login-bg">
    
    <div class="login">
        <div class="message">WeAdmin 1.0-管理登录</div>
        <div id="darkbannerwrap"></div>
        
        <form method="post" class="layui-form" >
            <input name="account"  placeholder="用户名"  type="text" lay-verify="required" class="layui-input" >
            <hr class="hr15">
            <input name="password" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15">

            <div id ="captcha"  style="display:none">
                <input name="captchaCode" lay-verify="captcha" placeholder="验证码"  type="text" class="layui-input">
                <img id="captchaImg" alt="验证码" src="/getCaptcha" onclick="refreshCaptcha(this)"><br>
                <hr class="hr15">
            </div>


            <input class="loginin" value="登录" lay-submit lay-filter="login" style="width:48%;" type="submit">
            <button  class="layui-btn layui-btn-radius layui-btn-primary layui-btn-lg" type="reset" style="width: 48%;">取消</button>
            <hr class="hr15" >
        </form>
    </div>

    <script type="text/javascript">
        var captchaStatus = false;
        window.onload = function() {
            checkCaptchaStatus();
        }
        function refreshCaptcha(img){
            img.src='/getCaptcha?'+Math.random();
        }

        layui.extend({
				admin: '{/}../static/js/admin'
			});
            layui.use(['form'], function(){
              var form = layui.form;
              // layer.msg('玩命卖萌中', function(){
              //   //关闭后的操作
              //   })
               form.verify({
                   captcha: function (value, item) {
                       if (captchaStatus && !value.length>0) {
                           return"验证码不能为空";
                       }
                   }
               });
              //监听提交
              form.on('submit(login)', function(data){
                // alert(888)
                  var $ = layui.jquery ;
                  // layer.msg(JSON.stringify(data.field));
                  $.ajax({
                      type: "post",
                      dataType: "json",
                      url: "/admin/login",
                      contentType: "application/json;charset=UTF-8",//指定消息请求类型
                      data: JSON.stringify(data.field),
                      success: function (data) {
                          if(data.code == null || data.code != 200){
                              layer.msg(data.msg);
                              if(captchaStatus){
                                  $("#captchaImg").attr('src','/getCaptcha?'+Math.random());
                              }else{
                                  checkCaptchaStatus()
                              }
                          }else{
                              location.href='/templates/index.html';
                              localStorage.setItem('login', 1);

                          }
                      }
                  });
                return false;
              });
            });   
            function checkCaptchaStatus() {

                var $ = layui.jquery ;
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: "/getCaptchaStatus",
                    contentType: "application/json;charset=UTF-8",//指定消息请求类型
                    success: function (data) {
                        if(data.code == null || data.code != 200){
                            layer.msg(data.msg);
                        }else{
                            captchaStatus = data.data;
                            if (captchaStatus) {
                                $("#captcha").show();
                            }else {
                                $("#captcha").hide();
                            }
                        }
                    }
                });
            }
    </script>  
    <!-- 底部结束 -->
</body>
</html>